#!/bin/bash
set -e

DRIVERS_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT_DIR=$(
  cd "$DRIVERS_DIR" || exit 1
  cd "../kernel/208-9-0/" && pwd
)

export PATH=/opt/hcc_arm64le/bin:$PATH

for dir in "$DRIVERS_DIR"/*/; do
  if [ -d "$dir" ]; then
    # 进入每个同级文件夹，创建 tmp 目录
    (cd "$dir" && mkdir -p tmp
    cp *.c *.h Makefile tmp/
    cp /opt/hi1711sdk/Module.symvers "$(pwd)/tmp/Module_sdk.symvers"
    cd tmp && make KBUILD_EXTRA_SYMBOLS="$(pwd)/Module_sdk.symvers"
    cp -r *.ko "$SCRIPT_DIR" && cd ..
    rm -rf tmp
    echo "$dir compile completed.")
  fi
done

echo "Drivers compile completed."

